// components/contact/contact.js
const httprequest = require('../../../utils/http_utils.js')
const app = getApp()
Component({
  /**
   * 组件的属性列表
   */
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {
    navScrollLeft:0,
    currentTab: 0,
    phonelist: [],
    dataList:[], //数据集合
    list: [{
      text: "主页",
      iconPath: "/pages/images/home.png",
      selectedIconPath: "/pages/images/home_select.png",
    },
    {
      text: "通讯录",
      iconPath: "/pages/images/tel.png",
      selectedIconPath: "/pages/images/tel_select.png",
    },
    {
      text: "我的",
      iconPath: "/pages/images/mine.png",
      selectedIconPath: "/pages/images/mine_select.png",
    }
    ],
    // ProjectGuid: '',
    showzanwu: false, //是否显示暂无图片
    windowWidth: 0,
    title: '通讯录',
    customHeight: 0, //自定义高度
  },

  lifetimes: {
    // 生命周期函数，可以为函数，或一个在methods段中定义的方法名
    attached: function () {
      // var userinfo = wx.getStorageSync('UserInfo')
      // this.setData({
      //   ProjectGuid: userinfo.ProjectGuid
      // })
	  var that=this;
      that.setData({
        customHeight: (65 + app.globalData.titleBarHeight + app.globalData.statusBarHeight) * 2
      })
      console.log('---------导航栏高度--------' + that.data.customHeight)
	  setTimeout(function() {
		   that.getContactList();
	  }, 1500);
      that.getSystemInfo();
    },
  },

  /**
   * 组件的方法列表
   */
  methods: {
    switchTab(event) {
      var cur = event.detail.current;
      var singleNavWidth = this.data.windowWidth / 3;
      this.setData({
        currentTab: cur,
        navScrollLeft: (cur - 2) * singleNavWidth
      });
      this.getContactList();
    },
    tabChange(e) {
      console.log('tab change', e.detail.index)
      if (e.detail.index == 0) {
        wx.redirectTo({
          url: '../home/home',
        })
      } else if (e.detail.index == 1) {
        wx.redirectTo({
          url: '../contact/contact',
        })
      } else {
        wx.redirectTo({
          url: '../person/person',
        })
      }
    },
    //获取通讯录
    getContactList: function () {
      var that = this
      that.setData({
        showzanwu: false
      })
      var params = {
        ProjectGuid: wx.getStorageSync('UserInfo').AppLogin.ProjectGuid
      }
      httprequest.PostValidateRequest(httprequest.apiInfo.GetSchedulingAndUsesNewApi, params,
        function (res) {
          console.log(JSON.stringify(res)+"__________通讯录")
          if (res.length > 0) {
            that.setData({
              dataList:res
            })
          }else{
            that.setData({
              showzanwu: true
            })
          }
        },
        function (err) {
          console.error(err)
          that.setData({
            showzanwu: true
          })
        }
      )
    },
    phonecall: function (e) {
      wx.makePhoneCall({
        phoneNumber: e.currentTarget.dataset.phone,
      })
    },
    getSystemInfo: function () {
      var that = this
      wx.getSystemInfo({
        success: function (res) {
          that.setData({
            windowWidth: res.windowWidth
          })
        },
        fail: function (res) { },
        complete: function (res) { },
      })
    },
  }
})
